package goleetcode

import "sort"

func countWays(ranges [][]int) int {
	const mod = 1e9 + 7
	sort.Slice(ranges, func(i, j int) bool {
		return ranges[i][0] < ranges[j][0]
	})
	n := len(ranges)
	res := int64(1)
	for i := 0; i < n; {
		r := ranges[i][1]
		j := i + 1
		for j < n && ranges[j][0] <= r {
			r = max(r, ranges[j][1])
			j++
		}
		res = (res * 2) % int64(mod)
		i = j
	}
	return int(res)
}